package com.only4play.practice.ordercenter.core.controller;

import com.alibaba.nacos.shaded.com.google.common.collect.Lists;
import com.only4play.practice.common.enums.AccountType;
import com.only4play.practice.common.enums.OrderType;
import com.only4play.practice.ordercommon.pay.CoinPayItem;
import com.only4play.practice.ordercommon.pay.PayItem;
import com.only4play.practice.common.other.CodeValue;
import com.only4play.practice.ordercenter.api.WechatPay;
import com.only4play.practice.ordercenter.api.model.domainmodel.OrderItemModel;
import com.only4play.practice.ordercenter.api.model.domainmodel.OrderCreateModel;
import com.only4play.practice.ordercenter.core.service.IOrderBaseService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author mengdy
 */
@RestController
@RequestMapping("/main/test")
public class MainTestController {


    @Resource
    private IOrderBaseService orderBaseService;

    @RequestMapping(value = "/create/order/base",method = {RequestMethod.POST})
    public String test( OrderCreateModel model){

        if (model.getAccountId() == null){

            model = new OrderCreateModel();
            // 设置用户信息
            model.setAccountId(2L);
            model.setAccountType(AccountType.CORP);

            model.setOrderType(OrderType.SHOP);

            model.setOperateUser("管理员");

            //使用了哪些支付项，如硬币支付了一部分、线上支付了一部分、优惠券支付了一部分等
            // 还是说 直接传一个支付项列表，然后根据支付项列表来计算出实际支付金额
            // 或者说 后面支付中心需要用到这个列表的配置决定调用的第三方接口
            List<PayItem> payItemList = Lists.newArrayList();
            WechatPay wechatPay = new WechatPay();

            CoinPayItem coinPayItem = new CoinPayItem(new BigDecimal(8));
            payItemList.add(wechatPay);
            payItemList.add(coinPayItem);

            model.setPayList(payItemList);

            List<CodeValue> attrs = Lists.newArrayList();
            CodeValue kv = new CodeValue();
            kv.setK("channel");
            kv.setV("ios");
            kv.setL("渠道");
            attrs.add(kv);

            CodeValue kv1 = new CodeValue();
            kv1.setK("city");
            kv1.setV("河北");
            kv1.setL("城市");
            attrs.add(kv1);

            CodeValue kv2 = new CodeValue();
            kv2.setK("shop");
            kv2.setV("二号店");
            kv2.setL("二号店");
            attrs.add(kv2);
            model.setAttrs(attrs);

            List<OrderItemModel> itemModels = Lists.newArrayList();
            OrderItemModel orderItemModel = new OrderItemModel();
//            orderItemModel.setSkuId("1L");
            orderItemModel.setItemCount(1);
            orderItemModel.setFeeRemark("衣服一件");
            orderItemModel.setGoodsName("衣服");
//            orderItemModel.setRealAmount(10320L);
            OrderItemModel orderItemModel2 = new OrderItemModel();
//            orderItemModel2.setSkuId("2L");
            orderItemModel2.setItemCount(1);
            orderItemModel2.setFeeRemark("鞋子");
            orderItemModel2.setGoodsName("鞋子");
//            orderItemModel2.setRealAmount(10602L);
            itemModels.add(orderItemModel);
            itemModels.add(orderItemModel2);
            model.setItemInfoList(itemModels);
        }

        orderBaseService.createOrder(model);
        return "hello world";
    }

    public static void main(String[] args) {

        try {
            long aLong = Long.parseLong(null);
        }catch (Exception e){
            System.out.println(e.getMessage());
            System.out.println(e.toString());
        }

    }
}
